package pers.linkong.asr.util;

import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;

import pers.linkong.asr.domain.VRBean;
import pers.linkong.asr.domain.VRContainerBean;
import pers.linkong.asr.domain.VRDateBean;
import pers.linkong.asr.service.VisualService;

public class VisualKit {
	public static List<VRContainerBean> CourseVisual(int cid, VisualService visualService) throws Exception{
		List<VRContainerBean> vrcb = new ArrayList<VRContainerBean>();
		// 获取差的天数
		long daynum = visualService.getDifference(cid);
		int k;
		// 循环这个差的天数次，每次天数加1
		for(int i = 0; i < daynum; i++){
			List<VRDateBean> visualBeans = visualService.getDate(cid, i+1);
			//判断当天是否有课
			k = 0;
			if(visualBeans.size() == 0){
				//没课执行下一次循环
				continue;
			} else {
				//有课开始仔细查看课程是否符合要求
				Timestamp date = visualBeans.get(0).getDate();
				System.out.println(date + "发现了课程，子级个数:" + visualBeans.size());
				int weeknum = visualService.getWeekNum(cid, date);
				if(weeknum == 0){
					break;
				}
				for(int j = 0; j < visualBeans.size(); j++){
					System.out.println(Thread.currentThread().getStackTrace()[1].getClassName() + "正在检查当前课程的第" + weeknum + "周");
					ResultInfo resultInfo =  StringKit.selectNumInStr(visualBeans.get(j).getWeekNumber(), weeknum);
					System.out.println(Thread.currentThread().getStackTrace()[1].getClassName() + "：" +"code:" +resultInfo.getCode() + " " + resultInfo.getMsg());
					if(resultInfo.getCode() == 1){
						k++;
						List<VRBean> list = visualService.getStuRecore(visualBeans.get(j).getCidSublevel(), date);
						if(k == 1){
							vrcb.add(VRContainerBean.data(TimeKit.TSFormatMD(date), list));
						} else {
							vrcb.add(VRContainerBean.data(TimeKit.TSFormatMD(date) + " (" + k + ")", list));
						}
					}
				}
			}
		}
		return vrcb;
	}
}
